library(dplyr)
library(plotly)
# Access key token
Sys.setenv('MAPBOX_TOKEN' = 'pk.eyJ1IjoiYnJpbWEiLCJhIjoiY2ptYm5pbXZ6MDd1czNwcW10OHN4Y2theSJ9.SNmXpvkIL14Wn1ebhRr_ug')
aegypti <- read.csv("aegypti_albopictus.csv", header = TRUE, sep = ",")
aegypti %>%
  select(VECTOR, Y, X, YEAR, COUNTRY) %>%
  filter(YEAR == 2004) %>%
  plot_mapbox(x = ~X, y =~Y, split = ~VECTOR, mode = "scattermapbox", hoverinfo = "name" ) %>%
  layout( title = "Scatter plot of mosquitos 2004",
        mapbox = list(style = "light"),
        margin = list(r = 25, l = 25, b = 25, t = 25, pad = 0.5)
        )
# 2013 scatter plot of mosquitos
aegypti %>%
  select(VECTOR, Y, X, YEAR, COUNTRY) %>%
  filter(YEAR == 2013) %>%
  plot_mapbox(x = ~X, y =~Y, split = ~VECTOR, mode = "scattermapbox", hoverinfo = "name" ) %>%
  layout( title = "Scatter plot of mosquitos 2004",
        mapbox = list(style = "light"),
        margin = list(r = 25, l = 25, b = 25, t = 25, pad = 0.5)
        )
# compute z (no. of mosquitos detected per country); choropleth
aegypti %>%
  group_by(COUNTRY) %>%
  mutate(Z = n()) %>%
  plot_geo() %>%
  add_trace(
    z =~Z, name = 'Mosquito (Z)', color =~Z, color = "reds",
    locations =~COUNTRY_ID
  ) %>%
  layout(
    title = "Number of mosquitos detected per country",
    geo = list(
  projection = list(type = "equirectangular")
    )
  )
aegypti %>%
  group_by(COUNTRY) %>%
  mutate(Z = log(n())) %>%
  plot_geo() %>%
  add_trace(
    z =~Z, name = 'Mosquito (Z)', color =~Z, color = "reds",
    locations =~COUNTRY_ID
  ) %>%
  layout(
    title = "Number of mosquitos detected per country",
    geo = list(
  projection = list(type = "equirectangular")
    )
  )
aegypti %>%
  group_by(COUNTRY) %>%
  mutate(Z = log(n())) %>%
  plot_geo() %>%
  add_trace(
    z =~Z, name = 'Mosquito (Z)', color =~Z, color = "reds",
    locations =~COUNTRY_ID
  ) %>%
  layout(
    title = "Number of mosquitos detected per country",
    geo = list(projection = list(type = "conic"))
  )